package com.filetransfer;
import com.filetransfer.config.UserThemeConfiguration;
import com.filetransfer.utils.FontUtils;
import com.filetransfer.utils.ThemeLoader;
import com.filetransfer.view.MainFrame;
import com.formdev.flatlaf.FlatLightLaf;
import de.exlll.configlib.YamlConfigurations;
import lombok.extern.slf4j.Slf4j;

import javax.swing.*;
import java.nio.file.Path;
import java.nio.file.Paths;
@Slf4j
public class Main {
    public static final Path CONFIG_FILE_PATH = Paths.get("/tmp/config.yml");
    public static void main(String[] args) {
        FontUtils.setGlobalFont();
        UserThemeConfiguration config = YamlConfigurations.update(CONFIG_FILE_PATH, UserThemeConfiguration.class);
//        new Thread(() -> {
//            initialize(config);
//        }).start();
        ThemeLoader themeLoader = new ThemeLoader();
        boolean themeApplied = false;
        try {
            for (Class<?> themeClass : themeLoader.getThemeClasses()) {
                if (themeClass.getSimpleName().equals(config.getThemeName())) {
                    themeLoader.applyTheme(themeClass);
                    themeApplied = true;
                    break;
                }
            }
        } catch (Exception e) {
            log.error("Failed to apply theme: " + e.getMessage());
        }
        if (!themeApplied) {
            FlatLightLaf.setup();
            log.info("Default theme applied.");
        }
        SwingUtilities.invokeLater(MainFrame::new);
    }
//    public static void initialize(UserThemeConfiguration configuration) {
//        configuration.updateMessagesFromServer();
//    }
}
